/**
 * 
 */
package com.seascape.swms.system.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;

/**
 * @author Lay
 *
 */
public class ShiroUtils {
	
	public static Subject login(String username,String password) {
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(username,password);
		subject.login(token);
		return subject;
	}

	public static String getPrincipal() {
		Object principal = SecurityUtils.getSubject().getPrincipal();
		if(principal!=null) {
			return (String)principal;
		}
		return null;
	}
}
